home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / serial1a / serialco.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-09-03  |  6.8 KB  |  226 lines

  1. VERSION 5.00
  2. Begin VB.Form frmSerial 
  3.    Caption         =   "Serial Comms"
  4.    ClientHeight    =   4680
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   5880
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   4680
  10.    ScaleWidth      =   5880
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.Timer TMRComm 
  13.       Enabled         =   0   'False
  14.       Interval        =   1000
  15.       Left            =   5430
  16.       Top             =   4230
  17.    End
  18.    Begin VB.Frame Frame1 
  19.       Caption         =   "Commands and Results"
  20.       ForeColor       =   &H00C00000&
  21.       Height          =   3015
  22.       Left            =   90
  23.       TabIndex        =   7
  24.       Top             =   1440
  25.       Width           =   5595
  26.       Begin VB.TextBox txtRec 
  27.          Enabled         =   0   'False
  28.          Height          =   1395
  29.          Left            =   120
  30.          MultiLine       =   -1  'True
  31.          ScrollBars      =   2  'Vertical
  32.          TabIndex        =   10
  33.          Tag             =   "NC"
  34.          Top             =   1500
  35.          Width           =   5355
  36.       End
  37.       Begin VB.CommandButton BTNSend 
  38.          Caption         =   "&Send Text"
  39.          Default         =   -1  'True
  40.          Enabled         =   0   'False
  41.          Height          =   375
  42.          Left            =   4020
  43.          TabIndex        =   9
  44.          Tag             =   "NC"
  45.          Top             =   1020
  46.          Width           =   1455
  47.       End
  48.       Begin VB.TextBox txt 
  49.          Enabled         =   0   'False
  50.          Height          =   315
  51.          Index           =   2
  52.          Left            =   120
  53.          TabIndex        =   8
  54.          Tag             =   "NC"
  55.          Top             =   540
  56.          Width           =   5355
  57.       End
  58.       Begin VB.Label Label1 
  59.          Caption         =   "Text Returned:"
  60.          Height          =   255
  61.          Index           =   3
  62.          Left            =   120
  63.          TabIndex        =   12
  64.          Top             =   1260
  65.          Width           =   1215
  66.       End
  67.       Begin VB.Label Label1 
  68.          Caption         =   "String to send to device:"
  69.          Height          =   255
  70.          Index           =   2
  71.          Left            =   120
  72.          TabIndex        =   11
  73.          Top             =   300
  74.          Width           =   3075
  75.       End
  76.       Begin VB.Shape Pic 
  77.          BorderStyle     =   0  'Transparent
  78.          FillColor       =   &H0000FFFF&
  79.          FillStyle       =   0  'Solid
  80.          Height          =   255
  81.          Left            =   5280
  82.          Shape           =   3  'Circle
  83.          Top             =   180
  84.          Width           =   195
  85.       End
  86.    End
  87.    Begin VB.Frame Frame2 
  88.       Caption         =   "Comm's"
  89.       ForeColor       =   &H00C00000&
  90.       Height          =   1215
  91.       Left            =   90
  92.       TabIndex        =   0
  93.       Top             =   120
  94.       Width           =   5595
  95.       Begin VB.CommandButton BTNCloseCom 
  96.          Cancel          =   -1  'True
  97.          Caption         =   "Close Port"
  98.          Enabled         =   0   'False
  99.          Height          =   435
  100.          Left            =   4380
  101.          TabIndex        =   4
  102.          Tag             =   "NC"
  103.          Top             =   660
  104.          Width           =   1035
  105.       End
  106.       Begin VB.CommandButton BTNOpenCom 
  107.          Caption         =   "Open Port"
  108.          Height          =   435
  109.          Left            =   4380
  110.          TabIndex        =   3
  111.          Tag             =   "NO"
  112.          Top             =   180
  113.          Width           =   1035
  114.       End
  115.       Begin VB.TextBox txt 
  116.          Height          =   315
  117.          Index           =   1
  118.          Left            =   1980
  119.          TabIndex        =   2
  120.          Tag             =   "NO"
  121.          Text            =   "2400,n,8,1"
  122.          Top             =   570
  123.          Width           =   1455
  124.       End
  125.       Begin VB.TextBox txt 
  126.          Height          =   315
  127.          Index           =   0
  128.          Left            =   1020
  129.          TabIndex        =   1
  130.          Tag             =   "NO"
  131.          Text            =   "COM1:"
  132.          Top             =   570
  133.          Width           =   855
  134.       End
  135.       Begin VB.Label Label1 
  136.          Caption         =   "Comm Settings:"
  137.          Height          =   255
  138.          Index           =   1
  139.          Left            =   1980
  140.          TabIndex        =   6
  141.          Top             =   330
  142.          Width           =   1335
  143.       End
  144.       Begin VB.Label Label1 
  145.          Caption         =   "Comm Port:"
  146.          Height          =   255
  147.          Index           =   0
  148.          Left            =   1020
  149.          TabIndex        =   5
  150.          Top             =   330
  151.          Width           =   915
  152.       End
  153.    End
  154. Attribute VB_Name = "frmSerial"
  155. Attribute VB_GlobalNameSpace = False
  156. Attribute VB_Creatable = False
  157. Attribute VB_PredeclaredId = True
  158. Attribute VB_Exposed = False
  159. Private Sub BTNCloseCom_Click()
  160.     TMRComm.Enabled = False
  161.     Call fin_com
  162.     SwitchTags
  163. End Sub
  164. Private Sub BTNOpenCom_Click()
  165.     If Not Init_Com(txt(0).Text, txt(1).Text) Then
  166.         MsgBox txt(0).Text & " Not available!"
  167.         Exit Sub
  168.     End If
  169.     SwitchTags
  170.     TMRComm.Enabled = True
  171. End Sub
  172. Private Sub BTNSend_Click()
  173.     If WriteCOM32(txt(2)) <> Len(txt(2)) Then
  174.         MsgBox "Error writing to comm's"
  175.         Exit Sub
  176.     End If
  177.     txtRec.Text = ""
  178.     Pic.FillColor = &HFF0000
  179. End Sub
  180. Private Sub TMRComm_Timer()
  181.     Dim Ans As String, i As Integer, RtnStr As String
  182.     Ans = ReadCommPure()
  183.     If Pic.FillColor = &HFFFFFF Then
  184.         Pic.FillColor = &H808080
  185.        Else
  186.         Pic.FillColor = &HFFFFFF
  187.     End If
  188.     If Ans = "" Then Exit Sub
  189.     Pic.FillColor = &HFF
  190.     For i = 1 To Len(Ans)
  191.         RtnStr = RtnStr & Hex(Asc(Mid$(Ans, i, 1))) & " "
  192.     Next
  193.     RtnStr = RtnStr & vbCrLf & vbCrLf & CleanStr(Ans)
  194.     txtRec.Text = RtnStr
  195.     FlushComm
  196. End Sub
  197. Function CleanStr(TextLine As String) As String
  198.     Dim i As Integer, RtnStr As String
  199.     RtnStr = ""
  200.     For i = 1 To Len(TextLine)
  201.         Select Case Asc(Mid$(TextLine, i, 1))
  202.             Case &H5D
  203.                 RtnStr = RtnStr & "<ACK>"
  204.             Case &H5B
  205.                 RtnStr = RtnStr & "<NAK>"
  206.             Case Is >= &H30
  207.                 RtnStr = RtnStr & Mid$(TextLine, i, 1)
  208.             Case 13
  209.                 RtnStr = RtnStr & "<CR>"
  210.             Case 10
  211.                 RtnStr = RtnStr & "<LF>"
  212.             Case Else
  213.                 RtnStr = RtnStr & "@"
  214.         End Select
  215.     Next i
  216.     CleanStr = RtnStr
  217. End Function
  218. Sub SwitchTags()
  219.     Dim xs As Control
  220.     For Each xs In Me
  221.         If xs.Tag <> "" Then
  222.             xs.Enabled = Not xs.Enabled
  223.         End If
  224.     Next
  225. End Sub
  226.